<template>
  <div class="publish-container">
    <el-card class="box-card">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>发布文章</el-breadcrumb-item>
      </el-breadcrumb>
    </el-card>
    <el-card class="box-card">
      <el-form ref="form" :model="article" label-width="80px">
        <el-form-item label="标题">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="内容">
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>
        <el-form-item label="封面">
          <el-radio-group v-model="article.cover.type">
            <el-radio :label="1">单图</el-radio>
            <el-radio :label="3">无图</el-radio>
            <el-radio :label="0">三图</el-radio>
            <el-radio :label="-1">自动</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="频道">
          <el-select v-model="article.channel_id" placeholder="请选择频道">
            <el-option
            :label="item.name"
            v-for="(item,index) in channels"
            :key="index"
            :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">发表</el-button>
          <el-button>存入草稿</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getChannels,publishArticle } from "@/api/article";
export default {
  data() {
    return {
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      channels: [], // 文章频道列表
      article: {
        title: "", //文章标题
        content: "", // 文章内容
        cover: {
          // 文章封面
          type: 0, // 封面类型
          images: [],
        },
        channel_id: null
      },
    };
  },
  created() {
    this.loadChannels();
  },
  methods: {
    loadChannels() {
      //   const obj = {
      //       a:{
      //           b:{
      //               c:123
      //           }
      //       }
      //   }
      //     console.log(obj.a.b.c)
      //     const {a:{b:{c}}} = obj
      //     console.log(c)
      getChannels().then(({ data: { data } }) => {
        this.channels = data.channels;
      });
    },
    onSubmit() {
      publishArticle(this.article).then(res=>{
        
      })
    },
  },
};
</script>

<style>
</style>